<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            //获取所有游记数据
            //获取数据后 进行渲染
           /* $.get("/travels",function (data) {
                $("#allTravels").renderValues(data);
            })*/

           //月推荐游记的显示
            $.get("/travels/commend",{"type":2,"pageSize":3},function (data) {
                $("#carouselExampleControls").renderValues(data,{

                    setHref:function (ele,val) {
                        var href = $(ele).attr("href")+val;
                        $(ele).attr("href",href);
                    }
                });
                $(".carousel-item:first").addClass("active");

            })

                //记录当前页
                var currentPage = 1;
                //总页数
                var totalPage;
                var dataList = [];

                //先查询第一个游记的记录
                $.get("/travels",{currentPage:currentPage,pageSize:3},function (data) {
                    console.log(data);
                    $.merge(dataList,data.list)
                    $("#allTravels").renderValues({list:dataList},{
                        setHref:function (ele,val) {
                          var href = $(ele).attr("href")+val;
                          $(ele).attr("href",href);
                        }
                    });
                    currentPage+=1;
                    totalPage = data.pages;
                });


                //屏幕滚动判断+翻页
                $(window).scroll(function () {
                    if ($(window).height()+$(window).scrollTop()>=$(document).height()){
                        if(currentPage<=totalPage){
                            $.get("/travels",{currentPage:currentPage,pageSize:3},function (data) {
                                $.merge(dataList,data.list);
                                $("#allTravels").renderValues({list:dataList},{
                                    setHref:function (ele,val) {
                                        var href = $(ele).attr("href")+val;
                                        $(ele).attr("href",href);
                                    }
                                });
                                currentPage+=1;
                            })
                        }else{
                            $(document).dialog({
                                autoClose: 2500,
                                content: "我是个有底线的人",
                            });
                        }
                    }
                })
        })
    </script>
</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner" >
            <div render-loop="list">
                <div class="carousel-item">
                <div class="border commend">
                    <a href="travelContent.html?id=" render-fun="setHref" render-key="list.TravelId">
                        <img render-src="list.commendCoverUrl" width="100%" height="200px">
                        <h1 render-html="list.commendTitle"> </h1>
                        <small render-html="list.commendSubTitle"></small>
                    </a>
                </div>
            </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>

</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels">


        <div render-loop="list">
        <div class="row detail">
            <div class="col">
                <a href="travelContent.html?id=" render-fun="setHref" render-key="list.id" >
                    <h4 render-html="list.title"> </h4>
                </a>
                <p>
                    <!--点击用户查看当前用户是谁-->
                    <a href="userProfiles.html" >
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName">dafei</span> </a> 在
                    <span class="addr" render-html="list.place.name" >成都</span>

                </p>
                <p>
                    <i class="fa fa-eye fa-fw"></i>
                    <span></span>
                    <i class="fa fa-commenting fa-fw"></i>
                    <span render-html="list.comments"></span>
                </p>
            </div>
            <div class="col bigimg">
                <a href="travelContent.html?id=" render-fun="setHref" render-key="list.id" >
                    <img render-src="list.coverUrl">
                </a>
            </div>
        </div>
        </div>


    </div>
</div>



</body>

</html>